package cn.vendsystem.com.controller;

import cn.vendsystem.com.utils.MinioUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/files")
@RequiredArgsConstructor
public class FileController {

    private final MinioUtil minioUtil;

    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String upload(@RequestParam("file") MultipartFile file) throws Exception {
        String url = minioUtil.uploadFile(
                file.getInputStream(),
                file.getSize(),
                file.getContentType(),
                file.getOriginalFilename()
        );
        return url;
    }

    @DeleteMapping("/delete")
    public String delete(@RequestParam("objectName") String objectName) {
        minioUtil.deleteFile(objectName);
        return "删除成功";
    }
}
